package demo;

import com.sun.org.apache.xpath.internal.SourceTree;
import org.junit.Test;

import java.util.*;

/**
 * @Author: WWQ
 * @Date: 2019/4/3 11:07
 * @Version 1.0
 */
public class LambdaTest {

    @Test
    public void test() {
    }


    public void test2() {
        Comparator<Integer> comparator = (x1, x2) -> Integer.compare(x1, x2);
        TreeSet<Integer> treeSet = new TreeSet<Integer>(comparator);

        System.out.println();
    }

    List<Employee> emps = Arrays.asList(
            new Employee("张三", 18, 999.99),
            new Employee("李四", 28, 1999.99),
            new Employee("王五", 38, 2999.99),
            new Employee("赵六", 48, 3999.99)
    );

  	public List<Employee> filterEmployee(List<Employee> emps, MyPredicate<Employee> mp){
		List<Employee> list = new ArrayList<>();

		for (Employee employee : emps) {
			if(mp.test(employee)){
				list.add(employee);
			}
		}

		return list;
	}


    /**
     *Lamdab表达式
     */
    @Test
    public void test4(){
        List<Employee> list = filterEmployee(emps, (e) -> e.getAge() >=20);
        list.forEach(System.out::println);
    }

    /**
     * Stream API
     */
    @Test
    public void test3(){
        emps.stream().filter((e)->e.getSalary()>=2000).forEach(System.out::println);

        System.out.println("------------------------------------------------------------");

        emps.stream().filter((e)->e.getSalary()>=2000).map(Employee::getName).forEach(System.out::println);
    }
}
